<?php
/**
 * @todo 类
 * @copyright gaoxiang 2009
 * @author gaoxiang
 * @createdate 2009.03.17
 * @license 本程序遵照Creative Commons 署名-非商业性使用-相同方式共享 2.5 中国大陆 协议，该协议的中文版本可在http://creativecommons.org/licenses/by-nc-sa/2.5/cn/获得。
 **/
/* 数据库类 */
class MYSQL {
	private $db_host,$db_user,$db_pass,$db_database;
	public $arr_config_r;
	/* 构造函数 */
	public function __construct($db_host = 'localhost',$db_user = 'klniu',$db_pass= '68487256')
	{
		$this->arr_config_r = $arr_config_r;
		$this->db_host = $db_host;
		$this->db_user = $db_user;
		$this->db_pass = $db_pass;
		$this->db_database ='gdcopper_al';
		$this->connect_db();
	}
	/* 写入数据库表 参数为一条mysql查询语句*/
	public function write_table($query_write){
		if(mysql_query($query_write))
			return 1;
		else
			return 0;
	}
	/* 获得配置 多参数函数*/
	public function get_config(){
		$param_num = func_num_args();
		if ($param_num < 1){
			echo "ERROR:Please give one param at least !";
		}
		/* 参数连接获取查询 */
		for ($i = 0;$i < $param_num;++$i){
			$arr_param = func_get_arg($i); 
			$param .= ' or field= "'. $arr_param . '"';//数据库第二列为描述=field
		}
		$param_1 = strstr($param,"field");
		$result_1=mysql_query("select value from config where ($param_1)order by id");//数据库第三列为描述=config，第一列为id
		$i = 0;
		while($arr_config = mysql_fetch_assoc($result_1)){
			$this->arr_config_r[$i] = $arr_config[value];
			++$i;
		}
		
	}
	/*连接数据库*/
	public function connect_db()
	{
		$link_to_sql = mysql_connect($this->db_host,$this->db_user,$this->db_pass) or die ('Not connected : ' . mysql_error());
		mysql_select_db($this->db_database, $link_to_sql) or die ('Can\'t use klniu : ' . mysql_error());
		mysql_query("set names utf8",$link_to_sql);
	}
	
	/** @todo 获取生产记录
	  *	@参数 $pbegin=开始时间,$pend=结束时间,$pclient=客户,$pspec=规格,$prog=原料,$pmachine=机号,$pclass=班,$pgroup=组,$product_id=产品批号,$pmould=模具,$pjudge=判定结果,$pid=数据库序号,$affect_row=影响序列(这个参数决定怎么输入产品之后显示的结果)，默认0为全部
	  * @输出 查询结果
	  **/
	public function fetch_produce($pbegin=0,$pend=0,$pclient=0,$pspec=0,$prog=0,$pmachine='00',$pclass=0,$pgroup=0,$product_id=0,$pmould=0,$pjudge="0",$pid=0,$affect_row=0)
	{
		$query = "select pcreate_time,pclient,pspec,prog,product_id,pweight,pmould,pdefect,psurface,pjudge,premarks from produce where 1";
		$query_sum="select SUM(pweight) from produce where 1";
		$query_flash="SELECT SUM(dispremium) from disqualification where 1";
		if (is_date($pbegin) && is_date($pend)){
		$query .= " AND pcreate_time between '" . $pbegin . " 00:00:00' and '". $pend . " 23:59:59'";
		$query_sum .= " AND pcreate_time between '" . $pbegin . " 00:00:00' and '". $pend . " 23:59:59'";
		$query_flash .= " AND 	discreatedate between '" . $pbegin . " 00:00:00' and '". $pend . " 23:59:59'";}
		if ($pclient){
			$query .= " and pspec = '" . $pspec . "'";
			$query_sum .= " and pspec = '" . $pspec . "'";
		}
		if ($prog){
			$query .= " and prog = '" . $prog . "'";
			$query_sum .= " and prog = '" . $prog . "'";
		}
		if ($pmachine !='00'){
			$query .= " and pmachine = '" . $pmachine . "'";
			$query_sum .= " and pmachine = '" . $pmachine . "'";
			$query_flash .= " and dismachine = '" . $pmachine . "'";	
		}
		if ($pclass){
			$query .= " and pclass = '" . $pclass . "'";
			$query_sum .= " and pclass = '" . $pclass . "'";
			$query_flash .= " and disclass = '" . $pclass . "'";
		}
		if ($pgroup){
			$query .= " and pgroup =  '" . $pgroup . "'";
			$query_sum .= " and pgroup =  '" . $pgroup . "'";
			$query_flash .= " and disgroup =  '" . $pgroup . "'";
		}
		if ($product_id){
			$query .= " and product_id =  '" . $product_id . "'";
			$query_sum .= " and product_id =  '" . $product_id . "'";
		}
		if ($pmould){
			$query .= " and pmould = '" . $pmould . "'";
			$query_sum .= " and pmould = '" . $pmould . "'";
		}
		if ($pjudge){
			$query .= " and pjudge = '" . $pjudge . "'";
		}
		$query_sum_dis = $query_sum;
		$query_sum_wait = $query_sum;
		$query_sum .= " and pjudge = '合格'";
		$query_sum_dis .= " and pjudge = '不合格'";
		$query_sum_wait .=" and pjudge = '待检'";
		if ($pid){//此段为显示输入完成之后显示结果页面，以方便操作者检查
			$query .= " and pid >= ". $pid . " ORDER BY pcreate_time,product_id LIMIT " . $affect_row;
			$query_sum .= " and pid >= ". $pid . " ORDER BY pcreate_time,product_id LIMIT " . $affect_row;
			$query_sum_dis .= " and pid >= ". $pid . " ORDER BY pcreate_time,product_id LIMIT " . $affect_row;
			$query_sum_wait .= " and pid >= ". $pid . " ORDER BY pcreate_time,product_id LIMIT " . $affect_row;
		}else
		$query .= " ORDER BY pcreate_time,product_id";
		$qresult = mysql_query($query);
		if (!mysql_num_rows($qresult)){
			?>
			</tbody></table><div class="center-text">没有查询到结果！</div>
		<?php }else{?>
		<div style="padding:0 0 10px 50px;color:#0066CC;">合格品：<?php if($pjudge=="合格" || $pjudge=="0") echo (float)mysql_result(mysql_query($query_sum),0);else echo 0;?>Kg&nbsp;&nbsp;不合格品：<?php if($pjudge=="不合格" || $pjudge=="0") echo (float)mysql_result(mysql_query($query_sum_dis),0);else echo 0;?>Kg&nbsp;&nbsp;待检品：<?php if($pjudge=="待检" || $pjudge=="0") echo (float)mysql_result(mysql_query($query_sum_wait),0);else echo 0;?>Kg&nbsp;&nbsp;查询日期内该班组所有溢料：<?php echo (float)mysql_result(mysql_query($query_flash),0);?>Kg</div>
		<form id="outform" method="post" action="<?php echo $this->arr_config_r[0];?>action/outputxsl.php?action=product">
			<button type="button" class="positive" id="outputButton"  onclick="outputSend()" style="margin-left:448px;">导出EXCEL</button>&nbsp;&nbsp;<span id="message" class="gray" style="display:inline;">&nbsp;</span><input id="outmessage" type="hidden" name="content" value=""/></form>
			<?php $i = 1;
			while ($arr_result=mysql_fetch_array($qresult)){?>
				<tr <?php if($i%2 == 0) echo 'bgcolor="#E2E2E2"';?>>
					<td><?php echo $i;?></td>
					<td><?php echo substr($arr_result['pcreate_time'],0,10);?></td>
					<td><a href="<?php echo $this->arr_config_r[0] . 'rog.php?action=produce&id=' . $arr_result['prog']; ?>"><?php echo $arr_result['prog'];?></a></td>
					<td><?php echo  $arr_result['pclient'];?></td>
					<td><?php echo  $arr_result['pspec'];?></td>
					<td id="product<?php echo $i;?>"><?php echo  $arr_result['product_id'];?></td>
					<td><?php echo  $arr_result['pweight'];?></td>
					<td><?php echo  $arr_result['pmould'];?></td>
					<td><?php echo  $arr_result['pdefect'];?></td>
					<td><?php echo  $arr_result['psurface'];?></td>
					<td><?php echo  $arr_result['pjudge'];?></td>
					<td  width="100px"><?php echo  $arr_result['premarks'];?></td>
				</tr>				
			<?php  ++$i;} ?>
			<tbody></table>
	<?php 	}
	}
	
	/*获取生产记录并可编辑*/
	public function fetch_produce_ee($pbegin=0,$pend=0,$pclient=0,$pspec=0,$prog=0,$pmachine=0,$pclass=0,$pgroup=0,$product_id=0,$pmould=0,$pjudge="0",$puserid=0)
	{?>
		<div class="title">查询结果(单击修改)</div>
 	<form>
 	<table class="nosortable" style="table-layout: fixed;overflow: hidden;text-overflow: ellipsis; word-wrap: break-word;">
 		<thead>
	 	<tr>
	 		<th width="48px">序号</th>
	 		<th width="82px">日期</th>
	 		<th width="100px">投料批号</th>
	 		<th width="70px">客户</th>
	 		<th width="90px">规格</th>
	 		<th width="100px">产品批号</th>
	 		<th width="48px">重量</th>
	 		<th width="48px">模具</th>
	 		<th width="48px">伤点</th>
	 		<th width="70px">表面</th>
	 		<th width="80px">判定结果</th>
	 		<th width="100px">备注</th>
	 		<th bgcolor="#FFFFFF" width="20px"></th>
 		</tr>
 		</thead>
 		<tbody><?php
		global $arr_spec;
		$query = "select pcreate_time,pclient,pspec,prog,product_id,pweight,pmould,pdefect,psurface,pjudge,premarks from produce where 1";
		if (is_date($pbegin)&&is_date($pend)){
			$query .= " AND pcreate_time between '" . $pbegin . " 00:00:00' and '". $pend . " 23:59:59'";
		}
		if ($puserid){
			$query .= " and uuserid = '" . $puserid . "'";
		}
		if ($pclient){
			$query .= " and pspec = '" . $pspec . "'";
		}
		if ($prog){
			$query .= " and prog = '" . $prog . "'";
		}
		if ($pmachine !='00'){
			$query .= " and pmachine = '" . $pmachine . "'";	
		}
		if ($pclass){
			$query .= " and pclass = '" . $pclass . "'";
		}
		if ($pgroup){
			$query .= " and pgroup =  '" . $pgroup . "'";
		}
		if ($product_id){
			$query .= " and product_id =  '" . $product_id . "'";
		}
		if ($pmould){
			$query .= " and pmould = '" . $pmould . "'";
		}
		if ($pjudge){
			$query .= " and pjudge = '" . $pjudge . "'";
		}
		$query .= " ORDER BY pcreate_time,product_id";
		$qresult = mysql_query($query);
		if (!mysql_num_rows($qresult)){
			?>
			<tbody></table></form><div class="center-text">没有查询到结果！</div>
		<?php }else{
			$i = 1;
			while ($arr_result=mysql_fetch_array($qresult)){?>
				<tr id="row<?php echo $i;?>" <?php if($i%2 == 0) echo 'bgcolor="#E2E2E2"';?>>
					<td><?php echo $i;?></td>
					<td onclick="alter_state('<?php echo $i;?>','fdate','input',1,'product')">
						<span id="fdatespan<?php echo $i;?>" style="display:inline;"><?php echo substr($arr_result['pcreate_time'],0,10);?></span>
						<input name="fdateinput<?php echo $i;?>" type="text" id="fdateinput<?php echo $i;?>" value="<?php echo substr($arr_result['pcreate_time'],0,10);?>" style="display:none;width:80px;" size="8" maxlength="10" onblur="alter_state('<?php echo $i;?>','fdate','input',0,'product')"/>
						<img id="fdateimg<?php echo $i;?>" src="<?php echo $this->arr_config_r[0];?>/images/loading.gif" style="display:none;"/>
					</td>
					<td onclick="alter_state('<?php echo $i;?>','frog','input',1,'product')">
						<span id="frogspan<?php echo $i;?>" style="display:inline;"><?php echo $arr_result['prog'];?></span>
						<input name="froginput<?php echo $i;?>" type="text" id="froginput<?php echo $i;?>" value="<?php echo $arr_result['prog'];?>" style="display:none;width:97px;" size="12" maxlength="12" onblur="alter_state('<?php echo $i;?>','frog','input',0,'product')" />
						<img id="frogimg<?php echo $i;?>" src="<?php echo $this->arr_config_r[0];?>/images/loading1.gif" style="display:none;"  align="absmiddle"/>
					</td>
					<td onclick="alter_state('<?php echo $i;?>','fclient','input',1,'product')">
						<span id="fclientspan<?php echo $i;?>" style="display:inline;"><?php echo  $arr_result['pclient'];?></span>
						<input name="fclientinput<?php echo $i;?>" type="text" id="fclientinput<?php echo $i;?>" value="<?php echo  $arr_result['pclient'];?>" style="display:none;width:67px;" size="10" onblur="alter_state('<?php echo $i;?>','fclient','input',0,'product')"/>
						<img id="fclientimg<?php echo $i;?>" src="<?php echo $this->arr_config_r[0];?>/images/loading1.gif" style="display:none;"  align="absmiddle"/>
					</td>
					<td onclick="alter_state('<?php echo $i;?>','fspec','select',1,'product')">
						<span id="fspecspan<?php echo $i;?>" style="display:inline;"><?php echo  $arr_result['pspec'];?></span>
						<select name="fspecselect<?php echo $i;?>" id="fspecselect<?php echo $i;?>" style="display:none;text-align:center;width:90px;" onblur="alter_state('<?php echo $i;?>','fspec','select',0,'product')">
							<?php
							$j=0; 
							while (isset($arr_spec[$j])){ ?>
								<option value="<?php echo $arr_spec[$j];?>" <?php if ($arr_result['pspec']==$arr_spec[$j]) echo "selectd";?>><?php echo $arr_spec[$j];?></option>
							<?php ++$j;} ?>	
						</select>
						<img id="fspecimg<?php echo $i;?>" src="<?php echo $this->arr_config_r[0];?>/images/loading1.gif" style="display:none;"  align="absmiddle"/>
					</td>
					<td onclick="alter_state('<?php echo $i;?>','fproduct','input',1,'product')">
						<span id="fproductspan<?php echo $i;?>" style="display:inline;"><?php echo  $arr_result['product_id'];?></span>
						<input name="fproductinput<?php echo $i;?>" type="text" id="fproductinput<?php echo $i;?>" value="<?php echo $arr_result['product_id'];?>" style="display:none;width:97px;" size="12" maxlength="12" onblur="alter_state('<?php echo $i;?>','fproduct','input',0,'product')" />
						<img id="fproductimg<?php echo $i;?>" src="<?php echo $this->arr_config_r[0];?>/images/loading1.gif" style="display:none;"  align="absmiddle"/>
					</td>
					<td onclick="alter_state('<?php echo $i;?>','fweight','input',1,'product')">
						<span id="fweightspan<?php echo $i;?>" style="display:inline;"><?php echo  $arr_result['pweight'];?></span>
						<input name="fweightinput<?php echo $i;?>" type="text" id="fweightinput<?php echo $i;?>" value="<?php echo $arr_result['pweight'];?>" style="display:none;width:40px;" size="4" maxlength="4" onblur="alter_state('<?php echo $i;?>','fweight','input',0,'product')" />
						<img id="fweightimg<?php echo $i;?>" src="<?php echo $this->arr_config_r[0];?>/images/loading1.gif" style="display:none;"  align="absmiddle"/>
					</td>
					<td onclick="alter_state('<?php echo $i;?>','fmould','input',1,'product')">
						<span id="fmouldspan<?php echo $i;?>" style="display:inline;"><?php echo  $arr_result['pmould'];?></span>
						<input name="fmouldinput<?php echo $i;?>" type="text" id="fmouldinput<?php echo $i;?>" value="<?php echo $arr_result['pmould'];?>" style="display:none;width:30px;" size="3" maxlength="3" onblur="alter_state('<?php echo $i;?>','fmould','input',0,'product')" />
						<img id="fmouldimg<?php echo $i;?>" src="<?php echo $this->arr_config_r[0];?>/images/loading1.gif" style="display:none;"  align="absmiddle"/>
					</td>
					<td onclick="alter_state('<?php echo $i;?>','fdefect','input',1,'product')">
						<span id="fdefectspan<?php echo $i;?>" style="display:inline;"><?php echo  $arr_result['pdefect'];?></span>
						<input name="fdefectinput<?php echo $i;?>" type="text" id="fdefectinput<?php echo $i;?>" value="<?php echo $arr_result['pdefect'];?>" style="display:none;width:30px;" size="2" maxlength="3" onblur="alter_state('<?php echo $i;?>','fdefect','input',0,'product')" />
						<img id="fdefectimg<?php echo $i;?>" src="<?php echo $this->arr_config_r[0];?>/images/loading1.gif" style="display:none;"  align="absmiddle"/>
					</td>
					<td onclick="alter_state('<?php echo $i;?>','fsurface','input',1,'product')">
						<span id="fsurfacespan<?php echo $i;?>" style="display:inline;" ><?php echo  $arr_result['psurface'];?></span>
						<input name="fsurfaceinput<?php echo $i;?>" type="text" id="fsurfaceinput<?php echo $i;?>" value="<?php echo $arr_result['psurface'];?>" style="display:none;width:68px;" size="10" maxlength="40" onblur="alter_state('<?php echo $i;?>','fsurface','input',0,'product')" />
						<img id="fsurfaceimg<?php echo $i;?>" src="<?php echo $this->arr_config_r[0];?>/images/loading1.gif" style="display:none;"  align="absmiddle"/>
					</td>
					<td onclick="alter_state('<?php echo $i;?>','fjudge','select',1,'product')">
						<span id="fjudgespan<?php echo $i;?>" style="display:inline;"><?php echo $arr_result['pjudge'];?></span>
						<select style="display:none;text-align:center;width:70px;" name="fjudgeselect<?php echo $i;?>" id="fjudgeselect<?php echo $i;?>" onblur="alter_state('<?php echo $i;?>','fjudge','select',0,'product')">
							<option value="合格" <?php if ($arr_result['pjudge']=="合格") echo 'selected="selected"';?>>合格</option>
							<option value="不合格" <?php if ($arr_result['pjudge']=="不合格") echo 'selected="selected"';?>>不合格</option>
							<option value="待检" <?php if ($arr_result['pjudge']=="待检") echo 'selected="selected"';?>>待检</option>	
						</select>
						<img id="fjudgeimg<?php echo $i;?>" src="<?php echo $this->arr_config_r[0];?>/images/loading1.gif" style="display:none;"  align="absmiddle"/>
					</td>
					<td onclick="alter_state('<?php echo $i;?>','fremarks','input',1,'product')">
				 					<span id="fremarksspan<?php echo $i;?>" style="display:inline;"><?php echo  $arr_result['premarks'];?></span>
									 <input name="fremarksinput<?php echo $i;?>" type="text" id="fremarksinput<?php echo $i;?>" value="<?php echo $arr_result['premarks'];?>" style="display:none;width:97px;" size="10" maxlength="40" onblur="alter_state('<?php echo $i;?>','fremarks','input',0,'product')" />
									 <img id="fremarksimg<?php echo $i;?>" src="<?php echo $this->arr_config_r[0];?>/images/loading1.gif" style="display:none;"  align="absmiddle"/>
				    </td>
				    <td><img src="<?php echo $this->arr_config_r[0];?>images/chk_off.png" title="删除" style="display:inline;" id="fdeleteimg<?php echo $i;?>" onclick="dedo('<?php echo $i;?>',0)"/></td>
				</tr>				
			<?php ++$i;} ?>
			<tbody></table></form>
	<?php 	}
	}
	/* 获取数据，返回查询到的数组 */
	public function fetch_row($query){
		$name = mysql_fetch_row(mysql_query($query));
		return $name;
	}
	/** @todo 获取一个月的待检品数量，或者全部清单
	 *  @参数 $isnum 表示要数量还是输出结果，1为数量,2为仅查看，3为可编辑
	 *  @输出 返回数量或者输出清单
	 **/
	public function fetch_inspection($isnum){
		$now=getdate();
		$month_ago=$now[0]-30*24*3600;
		if($isnum==1){
			$now_time=date("Y-m-d H:i:s");
			$month_ago_time=date("Y-m-d H:i:s",$month_ago);
			$query="SELECT pid from produce where pcreate_time between '$month_ago_time' and '$now_time' and pjudge='待检'";
			return mysql_num_rows(mysql_query($query));
		}elseif($isnum==2){
			$now_time=date("Y-m-d");
			$month_ago_time=date("Y-m-d",$month_ago);
			result_header("待检品");
			$this->fetch_produce($month_ago_time,$now_time,0,0,0,"00",0,0,0,0,"待检",0,0);
		}elseif($isnum==3){
			$now_time=date("Y-m-d");
			$month_ago_time=date("Y-m-d",$month_ago);
			?>
			<div class="title">待检品(单击判定结果修改)</div>
 	<form>
 	<table class="nosortable" style="table-layout: fixed;overflow: hidden;text-overflow: ellipsis; word-wrap: break-word;">
 		<thead>
	 	<tr>
	 		<th width="48px">序号</th>
	 		<th width="70px">日期</th>
	 		<th>投料批号</th>
	 		<th width="70px">客户</th>
	 		<th width="70px">规格</th>
	 		<th>产品批号</th>
	 		<th width="48px">重量</th>
	 		<th width="48px">模具</th>
	 		<th width="48px">伤点</th>
	 		<th width="100px">表面</th>
	 		<th width="80px">判定结果</th>
	 		<th width="100px">备注</th>
 		</tr>
 		</thead>
 		<tbody><?php
		global $arr_spec;
		$query = "select pcreate_time,pclient,pspec,prog,product_id,pweight,pmould,pdefect,psurface,pjudge,premarks from produce where pcreate_time between '" . $month_ago_time . " 00:00:00' and '". $now_time . " 23:59:59' and pjudge = '待检' ORDER BY product_id";
		$qresult = mysql_query($query);
		if (!mysql_num_rows($qresult)){
			?>
			<tbody></table></form><div class="center-text">没有查询到结果！</div>
		<?php }else{
			$i = 1;
			while ($arr_result=mysql_fetch_array($qresult)){?>
				<tr id="row<?php echo $i;?>" <?php if($i%2 == 0) echo 'bgcolor="#E2E2E2"';?>>
					<td><?php echo $i;?></td>
					<td ><?php echo substr($arr_result['pcreate_time'],0,10);?></td>
					<td><?php echo $arr_result['prog'];?></td>
					<td><?php echo  $arr_result['pclient'];?></td>
					<td><?php echo  $arr_result['pspec'];?></td>
					<td><span id="fproductspan<?php echo $i;?>" style="display:inline;"><?php echo  $arr_result['product_id'];?></span></td>
					<td><?php echo  $arr_result['pweight'];?></td>
					<td><?php echo  $arr_result['pmould'];?></td>
					<td><?php echo  $arr_result['pdefect'];?></td>
					<td><?php echo  $arr_result['psurface'];?></td>
					<td onclick="alter_state('<?php echo $i;?>','fjudge','select',1,'product')">
						<span id="fjudgespan<?php echo $i;?>" style="display:inline;"><?php echo $arr_result['pjudge'];?></span>
						<select style="display:none;text-align:center;width:70px;" name="fjudgeselect<?php echo $i;?>" id="fjudgeselect<?php echo $i;?>" onblur="alter_state('<?php echo $i;?>','fjudge','select',0,'product')">
							<option value="合格" <?php if ($arr_result['pjudge']=="合格") echo 'selected="selected"';?>>合格</option>
							<option value="不合格" <?php if ($arr_result['pjudge']=="不合格") echo 'selected="selected"';?>>不合格</option>
							<option value="待检" <?php if ($arr_result['pjudge']=="待检") echo 'selected="selected"';?>>待检</option>	
						</select>
						<img id="fjudgeimg<?php echo $i;?>" src="<?php echo $this->arr_config_r[0];?>/images/loading1.gif" style="display:none;"  align="absmiddle"/>
					</td>
					<td  width="100px" onclick="alter_state('<?php echo $i;?>','fremarks','input',1,'product')">
				 					<span id="fremarksspan<?php echo $i;?>" style="display:inline;"><?php echo  $arr_result['premarks'];?></span>
									 <input name="fremarksinput<?php echo $i;?>" type="text" id="fremarksinput<?php echo $i;?>" value="<?php echo $arr_result['premarks'];?>" style="display:none;width:98px;" size="10" maxlength="40" onblur="alter_state('<?php echo $i;?>','fremarks','input',0,'product')"/>
									 <img id="fremarksimg<?php echo $i;?>" src="<?php echo $this->arr_config_r[0];?>/images/loading1.gif" style="display:none;"  align="absmiddle"/>
				    </td>
				</tr>				
			<?php ++$i;} ?>
			<tbody></table></form>
		<?php }
		}
	}
	/** @todo 获取原材料记录
	  *	@参数 $begin=开始时间,$end=结束时间,$supplier=厂家代码,$spec=规格,$origin=供货批号,$raw=原料批号,$anneal=退火批号,$judge=判定结果,$userid=创建用户ID,$id=数据库序号,$affect_row=影响序列(这个参数决定怎么输入产品之后显示的结果)，默认0为全部
	  * @输出 查询结果
	  **/
	public function fetch_rog($begin=0,$end=0,$supplier=0,$make=0,$spec=0,$origin=0,$raw=0,$anneal=0,$technics='0',$judge="0",$userid,$id=0,$affect_row=0)
	{
		$query = "select stockdate,supplier,make,spec,weight,origin,raw,anneal,technics,tensile,extend,atensile,aextend,judge,remarks from rog where 1";
		$query_sum="select SUM(weight) from rog where 1";
		if (is_date($pbegin) && is_date($pend)){
			$query .= " AND pcreate_time between '" . $begin . " 00:00:00' and '". $end . " 23:59:59'";
			$query_sum .= " AND pcreate_time between '" . $begin . " 00:00:00' and '". $end . " 23:59:59'";
		}
		if ($supplier){
			$query .= " and supplier = '" . $supplier . "'";
			$query_sum .= " and supplier = '" . $supplier . "'";
		}
		if ($make){
			$query .= " and make = '" . $make . "'";
			$query_sum .= " and make = '" . $make . "'";
		}
		if ($spec){
			$query .= " and spec = '" . $spec . "'";
			$query_sum .= " and spec = '" . $spec . "'";
		}
		if ($origin){
			$query .= " and origin = '" . $origin . "'";
			$query_sum .= " and origin = '" . $origin . "'";	
		}
		if ($raw){
			$query .= " and raw = '" . $raw . "'";
			$query_sum .= " and raw = '" . $raw . "'";
		}
		if ($anneal){
			$query .= " and anneal =  '" . $anneal . "'";
			$query_sum .= " and anneal =  '" . $anneal . "'";
		}
		if($technics){
			$query .= " and technics =  '" . $technics . "'";
			$query_sum .= " and technics =  '" . $technics . "'";
		}
		if ($judge){
			$query .= " and judge =  '" . $judge . "'";
		}
		if ($userid){
			$query .= " and cuserid = '" . $userid . "'";
			$query_sum .= " and cuserid = '" . $userid . "'";
		}
		$query_sum_dis = $query_sum;
		$query_sum .= " and judge = '合格'";
		$query_sum_dis .= " and judge = '不合格'";
		if ($id){//此段为显示输入完成之后显示结果页面，以方便操作者检查
			$query .= " and id >= ". $pid . " ORDER BY stockdate,origin LIMIT " . $affect_row;
			$query_sum .= " and id >= ". $pid . " ORDER BY stockdate,origin LIMIT " . $affect_row;
			$query_sum_dis .= " and id >= ". $pid . " ORDER BY stockdate,origin LIMIT " . $affect_row;
		}else
		$query .= " ORDER BY stockdate,origin";
		$qresult = mysql_query($query);
		if (!mysql_num_rows($qresult)){
			?>
			</tbody></table><div class="center-text">没有查询到结果！</div>
		<?php }else{?>
		<div style="padding:0 0 10px 50px;color:#0066CC;">合格：<?php if($judge=="合格" || $judge=="0") echo (float)mysql_result(mysql_query($query_sum),0);else echo 0;?>Kg&nbsp;&nbsp;不合格品：<?php if($judge=="不合格" || $judge=="0") echo (float)mysql_result(mysql_query($query_sum_dis),0);else echo 0;?>Kg</div>
		<form id="outform" method="post" action="<?php echo $this->arr_config_r[0];?>action/outputxsl.php?action=rog">
			<button type="button" class="positive" id="outputButton"  onclick="outputSend()" style="margin-left:448px;">导出EXCEL</button>&nbsp;&nbsp;<span id="message" class="gray" style="display:inline;"></span><input id="outmessage" type="hidden" name="content" value=""/></form>
			<?php $i = 1;
			while ($arr_result=mysql_fetch_array($qresult)){?>
				<tr <?php if($i%2 == 0) echo 'bgcolor="#E2E2E2"';?>>
					<td><?php echo $i;?></td>
					<td><?php echo substr($arr_result['stockdate'],2);?></td>
					<td><?php echo $arr_result['supplier'];?></td>
					<td><?php echo  $arr_result['make'];?></td>
					<td><?php echo  $arr_result['spec'];?></td>
					<td><?php echo  $arr_result['weight'];?></td>
					<td><?php echo  $arr_result['origin'];?></td>
					<td id="<?php echo  'raw' . $i;?>"><?php echo  $arr_result['raw'];?></td>
					<td><?php echo  $arr_result['tensile'];?></td>
					<td><?php echo  $arr_result['extend'];?></td>
					<?php if($arr_result['anneal']==''){?>
							<td>未退火</td>
					<?php
					}else{?>
					<td><a href="#" onclick="echoAnneal('<?php echo $i;?>')">显示</a>
					<div class="echoanneal" id="<?php echo 'div' . $i;?>" onclick="_close('<?php echo $i;?>')">
					<table>
							<tr bgcolor="#E2E2E2">
 								<th width="100px">供货批号</th>
	 							<th width="100px">原料批号</th>
	 							<th width="60px">抗拉强度</th>
	 							<th width="45px">伸长率</th>
	 							<th width="100px">退火批号</th>
	 							<th width="100px">退火工艺</th>
	 							<th width="60px">抗拉强度</th>
	 							<th width="45px">伸长率</th>
							</tr>
							<tr>
								<td><?php echo  $arr_result['origin'];?></td>
								<td><?php echo  $arr_result['raw'];?></td>
								<td><?php echo  $arr_result['tensile'];?></td>
								<td><?php echo  $arr_result['extend'];?></td>
								<td><?php echo  $arr_result['anneal'];?></td>
								<td><?php echo  $arr_result['technics'];?></td>
								<td><?php echo  $arr_result['atensile'];?></td>
								<td><?php echo  $arr_result['aextend'];?></td>
							</tr>
						</table>
					</div></td>
					<?php }?>
					<td><?php echo  $arr_result['judge'];?></td>
					<td style="width:100px;"><?php echo  $arr_result['remarks'];?></td>
				</tr>				
			<?php  ++$i;} ?>
			</tbody></table>
	<?php 	}
	}
	/*析构函数*/
	public function __destruct() 
	{
		if (!($link_to_sql)){
            mysql_close();
		}	
	}
}
/* 新建对象 */
$database = new MYSQL($db_config['host'],$db_config['user'],$db_config['pass']);
?>